import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        a1201: props.values.a1201,
        zc9993: props.values.zc9993,
        a1204: props.values.a1204,
        a1207: props.values.a1207,
        a1211: props.values.a1211,
        a1214: props.values.a1214,
        a1217: props.values.a1217,
        a1221: props.values.a1221,
        a1224_2: props.values.a1224_2,
        a1227: props.values.a1227,
        a1231: props.values.a1231,
        a1233: props.values.a1233,
        a1234: props.values.a1234,
        a1235: props.values.a1235,
        a1237: props.values.a1237,
        a1238: props.values.a1238,
        a1240: props.values.a1240,
        a1241: props.values.a1241,
        a1224_1: props.values.a1224_1,
        a1224: props.values.a1224

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			}
*/
			if(formVals.a1204) {
      			formVals.a1204 = moment(formVals.a1204._d).format("YYYY-MM-DD");
      		}
			if(formVals.a1207) {
      			formVals.a1207 = moment(formVals.a1207._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file; 
			handleSubmitSubsetInfo(formVals,"update_for_staff_eduInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="学历名称">
			              {getFieldDecorator('a1201', {
			              rules: [{ required: true, message: '请选择'}],
			              initialValue: formVals.a1201,
			              })(
                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                    	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                    		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                    	}):null}
                    </Select>
                    )}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="学校(单位)名称">
                    {getFieldDecorator('a1214', {
                      rules: [{ required: true, message: '请选择'}],
                      initialValue: formVals.a1214,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="公安专业技术分类">
			              {getFieldDecorator('a1227',{
			              	initialValue: formVals.a1227,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              		{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
			              			return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              		}):null}
			              	</Select>
			              )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="入学日期">
			              {getFieldDecorator('a1204', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a1204?moment(formVals.a1204):null,
			              })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="毕(肄)业日期">
			              {getFieldDecorator('a1207', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a1207?moment(formVals.a1207):null,
			                  })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
			              </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="学制(年)">
			              {getFieldDecorator('a1211',{
			                rules: [{ required: false, message: '1-40个字符！'}],
                      initialValue: formVals.a1211,
			              })(
			              	<Input placeholder="1-40个字符" />
			              )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="所学专业代码">
			              {getFieldDecorator('a1224', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a1224,
			              })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('YB') != undefined?dicListByPcode('YB').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
                    )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="所学专业名称">
			              {getFieldDecorator('a1224_1', {
                    rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a1224_1,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="从学类别">
			              {getFieldDecorator('a1221', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a1221,
			                  })(
			                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			                      {dicListByPcode('YB') != undefined?dicListByPcode('YB').map((item,index) => {
			                        return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			                      }):null}
			                    </Select>
			                  )}
			              </FormItem>
			        </Col>

			       	<Col  md={12} sm={24}>
			       	  <FormItem  label="最高学历说明">
			       	      {getFieldDecorator('a1237', {
			       	        rules: [{ required: false, message: '请选择'}],
                      initialValue: formVals.a1237,
			       	        })(
                        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                          {dicListByPcode('YB') != undefined?dicListByPcode('YB').map((item,index) => {
                            return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                          }):null}
                        </Select>
                      )}
			       	  </FormItem>
			       	</Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col md={12} sm={24}>
			    	  <FormItem  label="记录状态">
			    	      {getFieldDecorator('a1233', {
			    	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1233,
			    	        })(
			    	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			    	        	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
			    	        		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			    	        	}):null}
			    	        </Select>
			    	      )}
			    	  </FormItem>
			    	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="多学历序号">
                  {getFieldDecorator('a1240', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1240,
                    })(
                     <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="学校(单位)所在政区">
          	      {getFieldDecorator('a1217', {
          	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1217,
          	        })(
          	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
          	        	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
          	        		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
          	        	}):null}
          	        </Select>
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="毕业院校类别">
                  {getFieldDecorator('a1241', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1241,
                    })(
                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                    	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
                    		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                    	}):null}
                    </Select>
                  )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="毕(肄)业证书编号">
          	      {getFieldDecorator('a1235', {
          	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1235,
          	        })(
          	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
          	        	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
          	        		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
          	        	}):null}
          	        </Select>
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="学习形式">
                  {getFieldDecorator('a1238', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1238,
                    })(
                     <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                     	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
                     		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                     	}):null}
                     </Select>
                  )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="学习完成情况">
          	      {getFieldDecorator('a1231', {
          	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a1231,
          	        })(
          	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
          	        	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
          	        		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
          	        	}):null}
          	        </Select>
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="学历描述">
                  {getFieldDecorator('a1234', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1234,
                    })(
                     <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          	<Col md={12} sm={24}>
                  <Button
                  	size="large"
                  	style={{marginRight: '10px'}}
                  	onClick={()=> {
                  		const { form } = this.props;
          				form.resetFields();
                  		cancelEditJobInfo(spinIndex);
                  	}}>
                  	取消
                 	</Button>
                  <Button size="large" type="primary" htmlType="submit">保存</Button>
              </Col>
          </Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="学历名称">
			              {getFieldDecorator('a1201')(<span>{formVals.a1201}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="学校(单位)名称">
			              {getFieldDecorator('a1214')(<span>{formVals.a1214}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="公安专业技术分类">
			              {getFieldDecorator('a1227')(<span>
			              	{(() => {
			              		return dicTextByCodePcode(formVals.a1227, 'AX');
				              	}
			             )()}
			            </span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="入学日期">
			              {getFieldDecorator('a1204')(<span>{formVals.a1204?moment(formVals.a1204).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="毕(肄)业日期">
			              {getFieldDecorator('a1207')(<span>{formVals.a1207?moment(formVals.a1207).format('YYYY-MM-DD'):null}</span>)}
			              </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="学制(年)">
			              {getFieldDecorator('a1211')(<span>{formVals.a1211}
			              	</span>)}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="所学专业代码">
			              {getFieldDecorator('a1224')(<span>{formVals.a1224}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="所学专业名称">
			              {getFieldDecorator('a1224_1')(<span>{formVals.a1224_1}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="从学类别">
			              {getFieldDecorator('a1221')(<span>{formVals.a1221}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="最高学历说明">
			              {getFieldDecorator('a1237')(<span>{formVals.a1237}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col  md={12} sm={24}>
				        <FormItem  label="记录状态">
				            {getFieldDecorator('a1233')(<span>{formVals.a1233}</span>)}
				        </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="多学历序号">
			              {getFieldDecorator('a1240')(<span>{formVals.a1240}
			              </span>)}
			          </FormItem>
			        </Col>

			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col  md={12} sm={24}>
                <FormItem  label="学校(单位)所在政区">
                    {getFieldDecorator('a1217')(<span>{formVals.a1217}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="毕业院校类别">
                    {getFieldDecorator('a1241')(<span>{formVals.a1241}
                    </span>)}
                </FormItem>
              </Col>

          </Row>


          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col  md={12} sm={24}>
                <FormItem  label="毕(肄)业证书编号">
                    {getFieldDecorator('a1235')(<span>{formVals.a1235}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="学习形式">
                    {getFieldDecorator('a1238')(<span>{formVals.a1238}
                    </span>)}
                </FormItem>
              </Col>

          </Row>


          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col  md={12} sm={24}>
                <FormItem  label="学习完成情况">
                    {getFieldDecorator('a1231')(<span>{formVals.a1231}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="学历描述">
                    {getFieldDecorator('a1234')(<span>{formVals.a1234}
                    </span>)}
                </FormItem>
              </Col>

          </Row>

			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
